package com.Brave.manager.Service;

import com.Brave.manager.Dao.TeacherDao;
import com.Brave.manager.Daomian.Teacher;

public class TeacherService {
    TeacherDao TeacherDao = new TeacherDao();

    public boolean isExists(String id) {
        Teacher[] teas = TeacherDao.findAllTeacher();
        boolean Exists = false;
        for (int i = 0; i < teas.length; i++) {
            Teacher tea = teas[i];
            if (tea != null && tea.getId().equals(id)) {
                Exists = true;
                break;
            }
        }
        return Exists;
    }

    public boolean addTeacher(Teacher tea) {
        return TeacherDao.addTeacher(tea);
    }

    public Teacher[] findAllTeacher() {
        Teacher[] teas = TeacherDao.findAllTeacher();
        boolean res = false;
        for (int i = 0; i < teas.length; i++) {
            Teacher tea = teas[i];
            if (tea != null) {
                res = true;
                break;
            }
        }
        if (res) {
            return teas;
        } else {
            return null;
        }
    }

    public void deleteTeacher(String id) {
        TeacherDao.deleteTeacher(id);
    }

    public void updateTeahcer(String id, Teacher tea) {
        TeacherDao.updateTeacher(id,tea);
    }
}
